<?php

namespace api\modules\v1\controllers\common;

use common\models\marketing\OutpatientType;
use Yii;
use api\controllers\OnAuthController;
use common\models\common\Config;
use common\helpers\CommonHelper;

/**
 * Class ConfigController
 * @package api\modules\v1\controllers\common
 */
class ConfigController extends OnAuthController
{
    /**
     * @var Config
     */
    public $modelClass = Config::class;

    /**
     * @api {get} /v1/common/config/index 全局配置列表
     * @apiName index
     * @apiGroup Config
     */
    public function actionIndexConfig()
    {
        // 查询结果
        $data = Yii::$app->services->config->getList($this->projectId);
        $where = ['status' => OutpatientType::STATUS_ENABLE];
        $outpatientType = Yii::$app->services->marketingOutpatientType->findList($where);
        return ['list' => $data, 'outpatient_type' => $outpatientType];
    }

    /**
     * @api {post} /v1/common/config/update 编辑全局配置
     * @apiName update
     * @apiGroup Config
     */
    public function actionUpdateConfig()
    {
        $params = Yii::$app->request->post();
        $params['project_id'] = $this->projectId;
        return Yii::$app->services->config->updateConfig($params);
    }
}